Options are | |
---|---|
text | Label of radio button. |
Bg / fg | set background / foreground color. |
width / height | The width / height of the button. |
command | A function that is called when the button is pressed. |
value |
|
variable |
|
from tkinter import * from tkinter.messagebox import * class MyFrame(Tk): def __init__(self): super().__init__() self.data=StringVar() self.data.set("Mr.") self.rbtn1=Radiobutton(self,text="Male",value="Mr.", variable =self.data,command=self.show) self.rbtn1.pack() self.rbtn2=Radiobutton(self,text="Female",value="Ms.", variable=self.data,command=self.show) self.rbtn2.pack() def show(self): showinfo(message="Hello "+self.data.get()+"Welcome to CCIT") frm=MyFrame() frm.mainloop()
from tkinter import * class MyFrame(Tk): def __init__(self): super().__init__() lst=["Red","Green","Blue","Orange"] self.color=StringVar() self.color.set("Red") for clr in lst: self.rbtn=Radiobutton(self,text=clr,value=clr,variable= self.color,command=self.show) self.rbtn.pack() self.lbl=Label(self,text="CCIT",fg="Red",font= "Helvetica 50 bold") self.lbl.pack() def show(self): clr=self.color.get() self.lbl.config(fg=clr) frm=MyFrame() frm.mainloop()